package com.cloudree.gllib.object;

import android.opengl.GLES20;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

/**
 * Created by Administrator on 2017/10/17 0017.
 */
public abstract class Shape {
    public static final int BYTES_PER_FLOAT = 4;
    protected FloatBuffer vertexBuffer;

    public Shape(float[] vertexData) {
        this.vertexBuffer = ByteBuffer.allocateDirect(vertexData.length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer()
                .put(vertexData);

        this.vertexBuffer.position(0);
    }

    /**
     * set attribute pointer
     */
    public void setAttributePointer(int position, int index, int size, int stride) {
        vertexBuffer.position(position);
        GLES20.glVertexAttribPointer(index, size, GLES20.GL_FLOAT, false, stride, vertexBuffer);
        GLES20.glEnableVertexAttribArray(index);
    }
}
